//
//  VipCenterVM.swift
//  LeTu
//
//  Created by gy on 2023/12/7.
//

import Foundation

class VipCenterVM {
    
    private(set) var pricesArr = [VipPirceModel]()
    
    // 获取会员价格表
    func getVipPriceList(isPayment: Bool = false, completeHandle: @escaping NetworkRequestHandle) {
        apiProvider.request(api: .getVipPriceList) { [weak self] json, jsonArr, code in
            
            MYLog("获取会员价格表: ", json)
            
            var dialog = DialogMessage()

            guard let strongSelf = self, let response = Mapper<ResponseModel>().map(JSON: json) else { return completeHandle(dialog) }
            dialog.code = response.code
            dialog.message = response.msg
            guard dialog.code == 200, let dataDic = response.data as? [[String: Any]] else { return completeHandle(dialog) }
            
            let tempPirces = Mapper<VipPirceModel>().mapArray(JSONArray: dataDic)
            if isPayment {
                strongSelf.pricesArr = tempPirces
            } else {
                strongSelf.pricesArr = tempPirces.filter({ $0.type > 0 })
            }

            completeHandle(dialog)
            
        } failureHandler: { error in
            completeHandle(DialogMessage())
        }

    }
    
}
